package com.runda.system.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.bbjob.dto.Result;
import com.bbjob.model.SysDictionary;
import com.runda.system.service.DicService;
import com.runda.util.DataEntity;


@RestController
@RequestMapping("sys/dic")
public class DictionaryController {
	
	@Resource
	private DicService dicservice;
	
	@RequestMapping(value = "saveDic", method = RequestMethod.POST)
	@ResponseBody
	public Result saveMenu(@RequestBody SysDictionary dic) {
		int ok = dicservice.saveDic(dic);
		if(ok > 0) {
			return new Result(200, "保存成功");
		}else {
			return new Result(8106,"保存失败");
		}
	}
	
	@RequestMapping(value = "editDic", method = RequestMethod.POST)
	@ResponseBody
	public Result editDic(@RequestBody SysDictionary dic) {
		int ok = dicservice.editDic(dic);
		if(ok > 0) {
			return new Result(200, "修改成功");
		}else {
			return new Result(8106,"修改失败");
		}
	}
	
	@RequestMapping(value = "deleteDic", method = RequestMethod.GET)
	@ResponseBody
	public Result deleteDic(Integer id) {
		int ok = dicservice.deleteDic(id);
		if(ok > 0) {
			return new Result(200, "删除成功");
		}else {
			return new Result(8106,"删除失败");
		}
	}
	
	@RequestMapping(value = "getDic", method = RequestMethod.GET)
	@ResponseBody
	public DataEntity getDic(SysDictionary dic) {
		return DataEntity.getInstance(dicservice.selectAll(dic));
	}
	
	@RequestMapping(value = "getDifficulty", method = RequestMethod.GET)
	@ResponseBody
	public DataEntity getDifficulty() {
		return DataEntity.getInstance(dicservice.getDifficulty());
	}
	
}
